package com.leyou.comtroller;


import com.leyou.common.vo.PageResult;
import com.leyou.dto.UserManageDTO;
import com.leyou.service.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
public class UserManageController {

    @Autowired
    private UserManageService userManageService;



//    @GetMapping("/aaa")
//    public ResponseEntity<String> test(){
//        PageResult<UserManageDTO> userManageDTOPageResult = userManageClient.queryUserManageByPage(1, 5);
//        System.out.println(userManageDTOPageResult);
//        return ResponseEntity.ok("123");
//    }

    //用户页面展示
    @GetMapping("/page")
    public ResponseEntity<PageResult<UserManageDTO>> queryUserManageByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5"  )Integer rows
    ){
        PageResult<UserManageDTO> pageResult = userManageService.queryUserManageByPage(page, rows);
        return ResponseEntity.ok(pageResult);
    }

    //添加员工信息
    @PostMapping("/member")
    public ResponseEntity<Void> addUserManage(@RequestBody UserManageDTO userManageDTO){
        userManageService.addUserManage(userManageDTO);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }


    //修改员工信息
    @PutMapping("/member")
    public ResponseEntity<Void>  updateUserManage(@RequestBody UserManageDTO userManageDTO){
        userManageService.updateUserManage(userManageDTO);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    //根据uid查找user
    @GetMapping("/member/{id}")
    public ResponseEntity<UserManageDTO> queryUserManageById(@PathVariable(value = "id") Long id){
        UserManageDTO userManageDTO = userManageService.queryUserManageById(id);
        return ResponseEntity.ok(userManageDTO);
    }

    //删除员工信息
    @DeleteMapping("/member/{id}")
    public ResponseEntity<Void> deleteUserManage(@PathVariable(value = "id")Long id){
        userManageService.deleteUserManage(id);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
